package com.cai.servlet.common.user.log;

import com.cai.dao.ProcessInfoCenterDao;
import com.cai.dao.impl.ProcessInfoCenterDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/common/log/ReplyProcessInfoMessage", name = "ServletReplyProcessInfoMessage")
public class ServletReplyProcessInfoMessage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int count;
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String replyMessage = req.getParameter("replyMessage");
        String messageId = req.getParameter("messageId");
        String userAccount = req.getParameter("userAccount");
        //检测是否存在该数据记录
        ProcessInfoCenterDao processInfoCenterDao = new ProcessInfoCenterDaoImpl();
        count = processInfoCenterDao.selectCountIsExit(Integer.parseInt(userAccount), Integer.parseInt(messageId));
        if (count != 0) {
            //管理员发送反馈给指定用户
           int data= processInfoCenterDao.replyProcessInfoMessage(Integer.parseInt(userAccount),Integer.parseInt(messageId),replyMessage);
           resp.getWriter().write(data);
        } else {
            resp.getWriter().write("0");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
